<template>
  <div class="container">
    <router-link
      class="back iconfont"
      to="/"
      tag="div"
      v-if="isShow"
    >&#xe624;</router-link>
    <div
      class="header"
      v-if="!isShow"
      :style="headerStyle"
    >{{sight}}</div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  props: {
    sight: String
  },
  data () {
    return {
      isShow: true,
      headerStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    getTop () {
      const top = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
      if (top > 10) {
        this.isShow = false
        this.headerStyle.opacity = top / 44
      } else {
        this.isShow = true
      }
    }
  },
  mounted () {
    window.addEventListener('scroll', this.getTop)
  },
  destroyed () {
    window.removeEventListener('scroll', this.getTop)
  }
}
</script>

<style lang="stylus" scoped>
@import "~@style/variables.styl"
.container
  .back
    text-align center
    line-height .8rem
    height .8rem
    width .8rem
    position absolute
    left .2rem
    top .2rem
    border-radius .4rem
    background-color rgba(0, 0, 0, .7)
    z-index 2
    color #fff
  .header
    background $bgcolor
    height $header
    color #fff
    font-size .32rem
    line-height $header
    text-align center
    position fixed
    top 0px
    left 0px
    right 0px
    z-index 2
</style>
